package core.demo;

import core.obj.Sort;
import javafx.util.Pair;

public class BubbleSort<T> extends Sort<T> {

    public BubbleSort(Comparable<T>[] arr){
        super(arr);
    }
    @Override
    public void sort() {
        for (int i = 0; i< arr.length-1; i++){
            for (int j = 0; j< arr.length-1-i; j++){
                pointers.addElement(new Pair<>(j,j+1));//指针过程添加
                if(arr[j].compareTo((T) arr[j+1])<0){
                    process.addElement(new Pair<>(j,j+1));//交换过程的添加
                    Comparable<T> temp= arr[j];
                    arr[j]= arr[j+1];
                    arr[j+1]=temp;
                }
            }
        }
    }
}
